package org.enwey.icarenew.Component;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.enwey.icarenew.Model.Topic;
import org.enwey.icarenew.Model.UserNew;
import org.enwey.icarenew.R;

/**
 * Created by John on 1/26/2015.
 */
public class UserNewItem extends LinearLayout {
    private TextView mTitle;
    private TextView mDate;
    private TextView mSupport;
    private TextView mComment;

    public UserNewItem(Context context) {
        super(context);
        initView();
    }

    public UserNewItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    private void initView() {
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.user_new_item, this);
        findView(view);
    }

    private void findView(View view) {
        mTitle = (TextView) view.findViewById(R.id.user_new_item_title);
        mDate = (TextView) view.findViewById(R.id.user_new_item_date);
        mSupport = (TextView) view.findViewById(R.id.user_new_item_support);
        mComment = (TextView) view.findViewById(R.id.user_new_item_comment);
    }

    public void setUserNew(Topic topic) {
        if (topic != null) {
            if (topic.title != null) {
                mTitle.setText(topic.title + "");
            }
            if (topic.date != null) {
                mDate.setText(topic.date + "");
            }
            if (topic.support != null) {
                mSupport.setText(topic.support + "");
            }
            if (topic.comment != null) {
                mComment.setText(topic.comment + "");
            }
        }
    }

}
